package com.apimarket.entity.kong;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class Route {
    private String id;

    @JsonProperty("created_at")
    private Date createdAt;

    @JsonProperty("updated_at")
    private Date updatedAt;

    @NotNull(message = "route名不能为空")
    private String name;

    private Service service;

    private List<String> protocols;

    @NotNull(message = "路由匹配的HTTP方法列表不能为空")
    private List<String> methods;

    private List<String> hosts;

    @NotNull(message = "路由匹配的路径列表不能为空")
    private List<String> paths;

    private String snis;

    private List<String> sources;

    private List<String> destinations;

    @JsonProperty("regex_priority")
    private int regexPriority;

    @JsonProperty("strip_path")
    private boolean stripPath;

    @JsonProperty("preserve_host")
    private boolean preserveHost;

    private List<String> tags;

    @JsonProperty("https_redirect_status_code")
    private int httpsRedirectStatusCode;

    private Map<String, Object> headers;

    @JsonProperty("path_handling")
    private String pathHandling;

    @JsonProperty("ws_id")
    private String wsId;

    /**
     * 初始化Route实例时，对一些
     * 基本数据类型赋予Kong规定的默认值
     */
    public Route() {
        this.httpsRedirectStatusCode = 426;
        this.protocols = Arrays.asList("http", "https");
        this.methods = Arrays.asList("GET", "POST", "OPTIONS", "DELETE", "PATCH", "PUT");
        this.stripPath = true;
        this.pathHandling = "v1";
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Service getService() {
        return service;
    }

    public void setService(Service service) {
        this.service = service;
    }

    public List<String> getProtocols() {
        return protocols;
    }

    public void setProtocols(List<String> protocols) {
        this.protocols = protocols;
    }

    public List<String> getMethods() {
        return methods;
    }

    public void setMethods(List<String> methods) {
        this.methods = methods;
    }

    public List<String> getHosts() {
        return hosts;
    }

    public void setHosts(List<String> hosts) {
        this.hosts = hosts;
    }

    public List<String> getPaths() {
        return paths;
    }

    public void setPaths(List<String> paths) {
        this.paths = paths;
    }

    public String getSnis() {
        return snis;
    }

    public void setSnis(String snis) {
        this.snis = snis;
    }

    public List<String> getSources() {
        return sources;
    }

    public void setSources(List<String> sources) {
        this.sources = sources;
    }

    public List<String> getDestinations() {
        return destinations;
    }

    public void setDestinations(List<String> destinations) {
        this.destinations = destinations;
    }

    public int getRegexPriority() {
        return regexPriority;
    }

    public void setRegexPriority(int regexPriority) {
        this.regexPriority = regexPriority;
    }

    public boolean isStripPath() {
        return stripPath;
    }

    public void setStripPath(boolean stripPath) {
        this.stripPath = stripPath;
    }

    public List<String> getTags() {
        return tags;
    }

    public boolean isPreserveHost() {
        return preserveHost;
    }

    public void setPreserveHost(boolean preserveHost) {
        this.preserveHost = preserveHost;
    }

    public void setTags(List<String> tags) {
        this.tags = tags;
    }

    public int getHttpsRedirectStatusCode() {
        return httpsRedirectStatusCode;
    }

    public void setHttpsRedirectStatusCode(int httpsRedirectStatusCode) {
        this.httpsRedirectStatusCode = httpsRedirectStatusCode;
    }

    public Map<String, Object> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, Object> headers) {
        this.headers = headers;
    }

    public String getPathHandling() {
        return pathHandling;
    }

    public void setPathHandling(String pathHandling) {
        this.pathHandling = pathHandling;
    }

    public String getWsId() {
        return wsId;
    }

    public void setWsId(String wsId) {
        this.wsId = wsId;
    }

    //这个Route的内部Service类，该Route属于哪个Service
    public static class Service {
        private String id;

        public Service() {
        }

        public Service(String id) {
            this.id = id;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        @Override
        public String toString() {
            final StringBuilder sb = new StringBuilder("Service{");
            sb.append("id='").append(id).append('\'');
            sb.append('}');
            return sb.toString();
        }
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Route{");
        sb.append("id='").append(id).append('\'');
        sb.append(", createdAt=").append(createdAt);
        sb.append(", updatedAt=").append(updatedAt);
        sb.append(", name='").append(name).append('\'');
        sb.append(", serviceId='").append(service).append('\'');
        sb.append(", protocols=").append(protocols);
        sb.append(", methods=").append(methods);
        sb.append(", hosts=").append(hosts);
        sb.append(", paths=").append(paths);
        sb.append(", snis='").append(snis).append('\'');
        sb.append(", sources=").append(sources);
        sb.append(", destinations=").append(destinations);
        sb.append(", regexPriority=").append(regexPriority);
        sb.append(", stripPath=").append(stripPath);
        sb.append(", preserveHost=").append(preserveHost);
        sb.append(", tags=").append(tags);
        sb.append(", httpsRedirectStatusCode=").append(httpsRedirectStatusCode);
        sb.append(", headers='").append(headers).append('\'');
        sb.append(", pathHandling='").append(pathHandling).append('\'');
        sb.append(", wsId='").append(wsId).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
